﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace Muehle
{
    public partial class NewPlayer : Background
    {
       
        public NewPlayer()
        {
            InitializeComponent();
            
        }

        private void savePlayer(object sender, EventArgs e)
        {
            bool alreadyUsed = false;
            for (int i = 0; i < (Application.Current as App).PlayerList.Count; i++)
            {
                Player temp = (Application.Current as App).PlayerList[i];
                if (temp.PlayerName.Equals(newPlayerName.Text))
                {
                    alreadyUsed = true;
                    break;
                }
            }

            if (alreadyUsed)
            {
                status.Text = "Player Name Already Taken!";
                return;
            }
            else
            {
                Player temp = new Player(newPlayerName.Text);
                List<Player> temp2 = new List<Player>();
                temp2.Add(temp);
                (Application.Current as App).PlayerList = temp2;
            }

            if (NavigationService.CanGoBack)
                NavigationService.GoBack();
        }
    }
}